package com.yun.util.listen;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class ExcelListener extends AnalysisEventListener<Class<?>>{

    final Logger logger = LoggerFactory.getLogger(ExcelListener.class);

    private final ApplicationContext applicationContext;
    private final Method method;
    private final Object instance;

    public ExcelListener(ApplicationContext applicationContext,Object instance,Method method) {
        this.applicationContext = applicationContext;
        this.method = method;
        this.instance = instance;
    }


    @Override
    public void invoke(Class<?> data, AnalysisContext context) {
        logger.info("接收到对象{}",data.toString());
        try {
            method.invoke(instance,data,applicationContext);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }



    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
    }

}

